﻿using JNPF.Basics.Models;
using JNPF.Data;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace JNPF.Basics.Logic
{
    /// <summary>
    /// 流程节点
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司（https://www.jnpfsoft.com）
    /// 作 者：JNPF开发平台组
    /// 日 期：2018-06-14 
    /// </summary>
    internal class FlowTaskNodeService : DataFactory, FlowTaskNodeIService
    {
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="taskId">任务主键</param>
        /// <returns></returns>
        public async Task<List<FlowTaskNodeEntity>> GetList(string taskId)
        {
            using (var db = this.Basic)
            {
                return await db.GetIQueryable<FlowTaskNodeEntity>().Where(m => m.TaskId == taskId).OrderBy(o => o.SortCode).ToListAsync();

            }
        }
        /// <summary>
        /// 信息
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
        public async Task<FlowTaskNodeEntity> GetInfo(string id)
        {
            using (var db = this.Basic)
            {
                return await db.GetEntityAsync<FlowTaskNodeEntity>(m => m.Id == id);
            }
        }
        /// <summary>
        /// 删除（根据实例Id）
        /// </summary>
        /// <param name="taskId">任务主键</param>
        /// <returns></returns>
        public async Task<int> DeleteByTaskId(string taskId)
        {
            using (var db = this.Basic)
            {
                return await db.DeleteAsync<FlowTaskNodeEntity>(m => m.TaskId == taskId);
            }
        }
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="entitys">实体对象</param>
        /// <returns></returns>
        public async Task<int> Create(List<FlowTaskNodeEntity> entitys)
        {
            using (var db = this.Basic)
            {
                return await db.InsertAsync(entitys);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public async Task<int> Update(FlowTaskNodeEntity entity)
        {
            using (var db = this.Basic)
            {
                return await db.UpdateAsync(entity);
            }
        }
    }
}